let app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let startParamObj = wx.getLaunchOptionsSync(); 
        console.log('startParamObj=>'+JSON.stringify(startParamObj));
        wx.setStorageSync('tabIndex',0);   
        let that = this;
        this.getMenu();
        //this.getOpen();
        app.autoUpdate().then(res=>{ 
            // console.log(11); 
            /*
             console.log(res);
             wx.reLaunch({
               url: '/pages/index/index',
             })
             */
             that.getOpen(); //that.wxLogIn();  
          })
    },
    getMenu:function(){
        let that = this;
        wx.request({
          url: app.globalData.domain+'wechat/login/getMenu',
          data:{from:1},
          success:res=>{
              console.log(res.data);
            //  that.setPageNavbar();
            var tab =res.data.menu;
              wx.setStorageSync('tabBar',res.data.menu);
              /*
              tabService.updateTabArray(this,tab);
              var tabIndex = wx.getStorageSync('tabIndex');
              var role=0;
              tabService.updateRole(this,role)
              tabService.updateIndex(this, tabIndex);
              */
          }
      })
      },    
    getOpen(){
        let that=this;
        var open=wx.getStorageSync('open');  
        console.log(open);
        if(open!="" && open!=undefined){
            wx.reLaunch({
                url: '/pages/index/index',
              })
      
        }else{     
            console.log('no info')      
            wx.login({
                success: res => {
              var code = res.code; 
              console.log('code='+code)         
             
                 wx.request({
                    url: app.globalData.domain+'wechat/login/getUnionId',
                    data: { code: code },
                    success: (res) => {
                      console.log(res.data);
                      //console.log(res.data.unionid);
                     // wx.setStorageSync('open', res.data)
                     var data=res.data;
                     if(data.open.id){
                       wx.setStorageSync('open', data.open);        
                    } 
                                
                      wx.reLaunch({
                        url: '/pages/index/index',
                      })
                   
                    }
                  })
                }})
    
             
    
            
          
            }
      },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})